import { Resume, IResume, ICategory } from '@/types';
import { defineStore } from 'pinia';
import { getUserResume } from '@/service/resume.service';
import { getResumeList } from '@/service/commodity.service';
import { ICommodityReq } from '@/types/params';
import { getCategory } from '@/service/catemory.service';

const useResumeStore = defineStore({
  /** 区分不通状态的唯一标识 */
  id: 'resume',
  /** 状态 */
  state: () => ({
    data: new Resume(),
    categoryList: [],
    // 页面onshow要不要重新加载
    reload: true,
  }),
  actions: {
    async getResume(): Promise<IResume> {
      this.data = await getUserResume();
      return this.data;
    },

    async getResumeList(params: ICommodityReq): Promise<IResume[]> {
      this.data = await getResumeList(params);
      return this.data;
    },

    /** 获取类目 */
    async getCategoryList(): Promise<ICategory[]> {
      if (this.categoryList.length) return this.categoryList;
      this.categoryList = await getCategory();
      return this.categoryList;
    },
  },
});
export { useResumeStore };
